﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T12OOP
{
    class Student
    {
        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private int age;

        //在属性中增加数据的约束
        public int Age
        {
            get { return age; }
            set
            {
                if (value <= 0 | value > 100)
                    throw new AccessViolationException("年龄参数异常");
                age = value;
            }
        }

        public override string ToString()
        {
            return string.Format("{0}:{1}", name, age);
        }
    }
}